package app.common;

import java.io.File;

public class ApplicationLocator {
    public static boolean isInTomcat() {
        return System.getProperty("catalina.home") != null;
    }

    public static String getAppDir() {
        String appDir = null;
        try {
            if (isInTomcat()) {
                appDir = System.getProperty("catalina.base") + File.separator;
                if (System.getProperty("wtp.deploy") == null) {
                    appDir += "webapps" + File.separator
                            + GlobalConstants.APP_NAME;
                    // ...\apache-tomcat-6.0.35\webapps
                } else {
                    appDir += "wtpwebapps" + File.separator
                            + GlobalConstants.APP_NAME;
                    // ...\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
                }
            } else {
                appDir = System.getProperty("user.dir");
                // ...\training\project\testjava
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return appDir;
    }
}
